<?
/*
* SETUP: README FIRST
* This script must be configured to be run every minute of every hour, ie 0001hs, 0101hs, 0201hs, etc...
*/

// No limit!
set_time_limit(0);

/*
* LOADING ADMIN MODULES CONFIG
*/
$confdir = dirname(__FILE__)."/../includes/";
if(file_exists($confdir."config.php"))
    require $confdir."config.php";
else if(file_exists($confdir."config.default.php"))
    require $confdir ."config.default.php";

require(DIR_INCLUDES."/functions.php");
require(DIR_INCLUDES."/functions_debug.php");

loadConfig();

/*
* LOADING MYSQL CONNECTION
*/
$dbLink = connectDb();
if (!$dbLink)
{
    die("Unable to connect to db.");
}

/*
* LOADING TRANSLATE OBJECT
*/
$lang = new adminLang();

$hour = date('H');
$minute = date('i');

/*
* LOOPING OVER MODULES!
*/
$modules = getAllModules();

foreach($modules AS $module)
{   
    if($module->enableCronjob)
    {
        $cronName = $module->id ."Cron";

        $lang->moduleID = $module->id;
        $lang->loadLang();

        $cronjob = new $cronName();
        $cronjob->setup($dbLink, $module, $lang);

        if($hour==1&&$minute==$cronjob->minuteOfHourStart)
        {
            // Daily cron jobs
            $cronjob->runDaily();
        }
        if($minute==$cronjob->minuteOfHourStart)
        {
            // Hourly cron jobs
            $cronjob->runHourly();
        }
        // Minutely cron jobs
        $cronjob->runMinutely();
    }
}

// Closing mysql connection
mysql_close($dbLink);

?>
